package com.han.hotelplat.cms.controller.hotel;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import com.han.hotelplat.comm.Constant;
import com.han.hotelplat.comm.ResponseWrapTo;
import com.han.hotelplat.comm.ResponseWrapTo.CodeType;
import com.han.hotelplat.comm.base.Pager;
import com.han.hotelplat.comm.utils.AreaHelp;
import com.han.hotelplat.comm.utils.HssfUtil;
import com.han.hotelplat.comm.utils.MsgHelp;
import com.han.hotelplat.comm.utils.RequestUtil;
import com.han.hotelplat.comm.utils.UUIDUtils;
import com.han.hotelplat.comm.utils.ValidateUtil;
import com.han.hotelplat.manager.LogManager;
import com.han.hotelplat.model.AreaModel;
import com.han.hotelplat.model.HotelLogModel;
import com.han.hotelplat.pojo.hhm.HotelHmanager;
import com.han.hotelplat.pojo.hotel.Hotel;
import com.han.hotelplat.pojo.hotelmanager.Hotelmanager;
import com.han.hotelplat.pojo.hotelroom.HotelRoom;
import com.han.hotelplat.pojo.log.Logger;
import com.han.hotelplat.pojo.systemuser.Systemuser;
import com.han.hotelplat.pojo.sysuserhotel.SysUserHotel;
import com.han.hotelplat.pojo.wallet.Wallet;
import com.han.hotelplat.service.hhm.HotelHmanagerService;
import com.han.hotelplat.service.hotel.HotelService;
import com.han.hotelplat.service.hotelmanager.HotelmanagerService;
import com.han.hotelplat.service.hotelroom.HotelRoomService;
import com.han.hotelplat.service.sysuserhotel.SysUserHotelService;
import com.han.hotelplat.service.wallet.WalletService;

@Controller
@RequestMapping("/cms/hotel")
public class CMSHotelController {
	@Autowired
	private HotelService hotelService;
	@Autowired
	private HotelmanagerService hotelmanagerService;
	@Autowired
	private WalletService walletService;
	@Autowired 
	private LogManager logManager;
	@Autowired
	private HotelHmanagerService hhmService;
	@Autowired
	private HotelRoomService hotelRoomService;
	@Autowired
	private SysUserHotelService sysUserHotelService;
	/**
	 * 导出管家列表
		 * @description	
		 * @author  han1088
		 * @param hotelId 酒店ID
		 * @param realName 管家姓名
		 * @param tel 管家电话
		 * @param pageNum 页码
	 */
	@ResponseBody
	@RequestMapping(value = "exportAllHotelManager", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public void exportAllHotelManager(HttpServletResponse resp, HttpServletRequest req,
			String startDate, String endDate, Integer position, String param){
		List<Hotelmanager> data = hotelmanagerService.exportAllHotelManager(startDate,endDate,position,param);
		String filename = "酒店管家.xls";
		resp.setHeader("Content-Type", "application/octet-stream");
		try {
			resp.setHeader("Content-Disposition", "attachment;filename=" + HssfUtil.buildAttachmentFileName(req, filename));
			List<Object[]> datas = new ArrayList<Object[]>();
			String[] columnNames = new String[] { "电话号码", "姓名", "职位","绑定的酒店数量", 
					"注册时间", "性别"};
			for(Hotelmanager hm : data){
				Object[] dataObj = new Object[columnNames.length];
				dataObj[0] = hm.getTel();
				dataObj[1] = hm.getRealname();
				Integer pt = hm.getPosition();
				dataObj[2] = "酒店管家";
				if(pt != null && pt.intValue() == 2){//领队
					dataObj[2] = "领队";
				}else if(pt != null && pt.intValue() == 3){//区域负责人
					dataObj[2] = "区域负责人";
				}
				
				dataObj[3] = hm.getHotelCount();
				dataObj[4] = hm.getCreattime();
				dataObj[5] = "男";
				Integer sex = hm.getSex();
				if(sex != null && sex.intValue() == 2){
					dataObj[5] = "女";
				}
				datas.add(dataObj);
			}
			HssfUtil.writeHssf("酒店管家表", columnNames, datas, filename, resp.getOutputStream());
		}catch(Exception e){
			
		}
	}
	
	@ResponseBody
	@RequestMapping(value = "addHotelManager", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String addHotelManager(String data){
		Hotelmanager oldHm = null;
		Hotelmanager hm = JSONObject.parseObject(data,
						Hotelmanager.class);
		if(hm.getTel() != null){//查看是否已经存在相同手机号的酒店管家
			oldHm = hotelmanagerService.findByTel(hm.getTel());
		}
	
		if(oldHm != null && hm.getId() == null){//已经存在相同手机号的管家则提示手机号已经存在了
			return new ResponseWrapTo(-1, "该手机号已经有对应的管家了不能新增酒店了", null).toJson();
		}else if(oldHm == null && hm.getId() == null){//不存在就创建管家
			hm.setUserid(UUIDUtils.getUUID()+"");
			hm.setCreattime(new Date());
			hm.setState(Constant.USER_STATE_PASS);
			hotelmanagerService.save(hm);
			return new ResponseWrapTo(CodeType.success, "管家添加成功", null).toJson();
		}
		oldHm.setSex(hm.getSex());
		oldHm.setPosition(hm.getPosition());
		oldHm.setIntroduceritel(hm.getIntroduceritel());
		oldHm.setUsername(hm.getTel());
		oldHm.setRealname(hm.getRealname());
		hotelmanagerService.update(oldHm);
		return new ResponseWrapTo(CodeType.success, "数据更新成功", data).toJson();
	}
	
	
	/**
	 *  获取管家详情
		 * @description	
		 * @author  han1088
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHMDetailInfo", produces = "application/json;charset=UTF-8", method = { RequestMethod.POST, RequestMethod.GET })
	public String getHMDetailInfo(String userid){
		Hotelmanager hm = hotelmanagerService.getHMDetailInfo(userid);
		return new ResponseWrapTo(CodeType.success, "数据获取成功", hm).toJson();
	}
	
	/**
	 *  获取管家数量按照时间统计
		 * @description	
		 * @author  han1088
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHMCountGroupDate", produces = "application/json;charset=UTF-8", method = { RequestMethod.POST, RequestMethod.GET })
	public String getHMCountGroupDate(){
		Map<String, Integer> data = hotelmanagerService.getHMCount();
		return new ResponseWrapTo(CodeType.success, "", data).toJson();
	}
	
	/**
	 * 酒店绑定管家获取管家列表
		 * @description	
		 * @author  han1088
		 * @param hotelId 酒店ID
		 * @param realName 管家姓名
		 * @param tel 管家电话
		 * @param pageNum 页码
	 */
	@ResponseBody
	@RequestMapping(value = "getAllHotelManager", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String getAllHotelManager(String startDate, String endDate, Integer position, String param, Integer pageNum){
		Pager<Hotelmanager> data = hotelmanagerService.findAllHotelManager(startDate,endDate,position,param,pageNum);
		return new ResponseWrapTo(CodeType.success, "数据获取成功", data).toJson();
	}
	
	/**
	 * 管家解除绑定关系
		 * @description	
		 * @author  han1088
		 * @param hotelId
		 * @param userid
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "untieHotelManager", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String untieHotelManager(Integer hotelId, String userid){
		Systemuser user = (Systemuser) RequestUtil.getSessionAttribute(Constant.CMS_SESSION_LOGIN_USER);
		List<HotelHmanager> li = hhmService.getBindHotelManager(hotelId, userid, null);
		if(li.size() >= 2){//数据有误，一个管家跟酒店的绑定关系只能有一条记录
			return new ResponseWrapTo(-1, "数据有误", null).toJson();
		}
		if(li.size() == 1){
			HotelHmanager hhm = li.get(0);
			if(hhm.getState().intValue() == 1){//已经绑定过了
				hhm.setUntietime(new Date());
				hhm.setState(2);//解绑
				hhm.setOptuser(user.getRealname());
				hhmService.save(hhm);
				
				Hotelmanager hm = hotelmanagerService.findByUserid(hhm.getHmuserid());//获取管家信息
				if(hm.getHotelid().intValue() == hhm.getHotelid()){//如果解绑的是用户已经绑定过的酒店
					//给一个默认的酒店
					List<HotelHmanager> re = hhmService.getBindHotelManager(null, hm.getUserid(), 1);
					if(re.size()>0){
						hm.setHotelid(re.get(0).getHotelid());
					}else{
						hm.setHotelid(null);
					}
					hotelmanagerService.update(hm);
				}
				return new ResponseWrapTo(CodeType.success, "解绑成功", null).toJson();
			}
		}
		
		return new ResponseWrapTo(-1, "未能查询到对应的数据", null).toJson();
	}
	
	/**
	 * 绑定管家
		 * @description	
		 * @author  han1088
		 * @param hotelId
		 * @param userid
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "bindHotelManager", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String bindHotelManager(Integer hotelId, String userid){
		Systemuser user = (Systemuser) RequestUtil.getSessionAttribute(Constant.CMS_SESSION_LOGIN_USER);
		List<HotelHmanager> li = hhmService.getBindHotelManager(hotelId, userid, null);
		if(li.size() >= 2){//数据有误，一个管家跟酒店的绑定关系只能有一条记录
			return new ResponseWrapTo(-1, "数据有误", null).toJson();
		}
		if(li.size() == 1){
			HotelHmanager hhm = li.get(0);
			if(hhm.getState().intValue() == 1){//已经绑定过了
				return new ResponseWrapTo(-1, "已经绑定过了", null).toJson();
			}else{
				hhm.setState(1);//重新绑定
				hhm.setBindtime(new Date());
				hhm.setUntietime(null);
				hhmService.save(hhm);
				return new ResponseWrapTo(CodeType.success, "绑定成功", null).toJson();
			}
		}
		Hotelmanager hm = hotelmanagerService.findByUserid(userid);
		Hotel h = hotelService.getHotelById(hotelId);
		HotelHmanager hhm = new HotelHmanager();
		hhm.setBindtime(new Date());
		hhm.setHmname(hm.getRealname());
		hhm.setHmtel(hm.getTel());
		hhm.setHmuserid(hm.getUserid());
		hhm.setHotelid(h.getId());
		hhm.setHotelname(h.getHotelname());
		hhm.setState(1);
		hhm.setOptuser(user.getRealname());
		hhmService.save(hhm);
		//管家首次绑定酒店
		if(hm.getHotelid() == null){
			hm.setHotelid(h.getId());
			hotelmanagerService.update(hm);//首次绑定设置管家的酒店ID
		}
		return new ResponseWrapTo(CodeType.success, "绑定成功", null).toJson();
	}
	
	/**
	 * 获取已经绑定该酒店的管家列表
		 * @description	
		 * @author  han1088
		 * @param hotelId 酒店ID
		 * @param realName 管家姓名
		 * @param tel 管家电话
		 * @param pageNum 页码
	 */
	@ResponseBody
	@RequestMapping(value = "getBindHotelManager", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String getBindHotelManager(Integer hotelId){
		if(hotelId == null){
			return new ResponseWrapTo(-1, "酒店ID不能为空", null).toJson();
		}
		List<Hotelmanager> data = hotelmanagerService.findBindHotelManager(hotelId);
		return new ResponseWrapTo(CodeType.success, "数据获取成功", data).toJson();
	}
	
	
	/**
	 * 酒店绑定管家获取管家列表
		 * @description	
		 * @author  han1088
		 * @param hotelId 酒店ID
		 * @param realName 管家姓名
		 * @param tel 管家电话
		 * @param pageNum 页码
	 */
	@ResponseBody
	@RequestMapping(value = "getHotelManager", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String getHotelManager(Integer hotelId, String param, Integer pageNum){
		if(hotelId == null){
			return new ResponseWrapTo(-1, "酒店ID不能为空", null).toJson();
		}
		Pager<Hotelmanager> data = hotelmanagerService.findHotelManager(hotelId,param,pageNum);
		return new ResponseWrapTo(CodeType.success, "数据获取成功", data).toJson();
	}
	
	
	/**
	 * 提交酒店资料
		 * @description	
		 * @author  han1088
		 * @param data
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "authHotel", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String authHotel(Integer hotelid, String userid, Integer state, String remark){
		Systemuser systemuser = (Systemuser) RequestUtil.getSessionAttribute(Constant.CMS_SESSION_LOGIN_USER);
		String cmsuserid = systemuser.getUserid();
		Hotel h = hotelService.getHotelById(hotelid);
		String message = "请填写：";
		if(state == Constant.HOTEL_STATE_PASS.intValue()){//提交审核通过的结果
			if(h.getTaskroomcount() == null){
				message = message+"【日均最低房量】";
			}
			if(h.getLevel() == null){
				message = message+"【清洁等级】";
			}
			/*if(h.getUnitprice() == null){
				message = message+"【清洁单价】";
			}
			if(h.getEmunitprice() == null){
				message = message+"【帮工单价】";
			}
			if(h.getHolidayprice() == null){
				message = message+"【酒店节假日单价】";
			}
			if(h.getHolidayemprice() == null){
				message = message+"【帮工节假日单价】";
			}*/
			if(h.getLocation() == null){
				message = message+"【酒店经纬度】";
			}
			if(!"请填写：".equals(message)){
				return new ResponseWrapTo(CodeType.fail, message, null).toJson();
			}
		}
		List<HotelHmanager> re= hhmService.getBindHotelManager(h.getId(), null, 1);
		h.setState(state);
		hotelService.update(h);
		//激活钱包
		if(state.intValue() == Constant.HOTEL_STATE_PASS.intValue()){
			Wallet w = walletService.getWallet(h.getId().toString());
			w.setState(Constant.WALLET_STATE_ACTIVE);
			walletService.update(w);
		}
		for(HotelHmanager hhm : re){
			try {
				//发送短信通知酒店
				MsgHelp.sendAuthHotelPass(hhm.getHmtel(), hhm.getHmname());
			} catch (ClientException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(state.intValue() == Constant.HOTEL_STATE_NOPASS.intValue()){
				try {
					//发送短信通知酒店
					MsgHelp.sendAuthHotelNoPass(hhm.getHmtel(), hhm.getHmname());
				} catch (ClientException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(state.intValue() == Constant.HOTEL_STATE_STOP.intValue()){
				try {
					//发送短信通知酒店
					MsgHelp.sendAuthUserStop(hhm.getHmtel(), hhm.getHmname(),Constant.USER_TYPE_HOTELMANAGER);
				} catch (ClientException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		String host = RequestUtil.getRequest().getRemoteHost();
		Logger logger = new Logger(new Date(), cmsuserid, host,systemuser.getRealname());
		
		HotelLogModel hlm = new HotelLogModel();
		hlm.setContext("审核酒店资料："+h.getHotelname()+";审核结果："+state);
		//hlm.setHmuid(hm.getUserid());
		hlm.setHotelid(h.getId());
		hlm.setHotelname(h.getHotelname());
		hlm.setOptcode(Constant.logger.LOG_HOTEL_AUTH);
		logManager.creatHotelLog(hlm, logger);
		
		return new ResponseWrapTo(CodeType.success, "审核成功", null).toJson();
	}
	
	/**
	 * 模糊查询酒店
		 * @description	
		 * @author  han1088
		 * @param data
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHotelByConditione", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST })
	public String getHotelByConditione(String condition){
		JSONArray jary = new JSONArray();
		boolean re = ValidateUtil.isSQLInject(condition);
		if(re){
			return new ResponseWrapTo(CodeType.success, "", jary).toJson();
		}
		Systemuser user = (Systemuser) RequestUtil.getSessionAttribute(Constant.CMS_SESSION_LOGIN_USER);
		String userid = user.getUserid();
		List<Hotel>li = hotelService.getHotelByConditione(condition,userid);
		for(Hotel h : li){
			JSONObject js = new JSONObject();
			js.put("hotelid", h.getId());
			js.put("hotelname", h.getHotelname());
			jary.add(js);
		}
		return new ResponseWrapTo(CodeType.success, "", jary).toJson();
	}
	
	/**
	 * 提交酒店资料
		 * @description	
		 * @author  han1088
		 * @param data
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "addHotel", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST })
	public String addHotel(String data){
		Systemuser user = (Systemuser) RequestUtil.getSessionAttribute(Constant.CMS_SESSION_LOGIN_USER);
		String userid = user.getUserid();
		JSONObject jobj = JSONObject.parseObject(data);
		JSONArray hotelroom = jobj.getJSONArray("hotelroom");
		JSONObject hotelJSObject = jobj.getJSONObject("hotel");
		List<HotelRoom> hrLi = null;
		if(hotelroom != null){
			hrLi = JSONObject.parseArray(hotelroom.toJSONString(),
					HotelRoom.class);
		}
		hotelJSObject.remove("areaModel");
		Hotel h = JSONObject.parseObject(hotelJSObject.toJSONString(),
				Hotel.class);
		if(h.getLevel()==null){
			h.setLevel(4);//默认清洁等级为4级
		}
		h.setCreattime(new Date());
		h.setWelfare(hotelJSObject.getString("welfare"));//酒店福利
		if(h.getId() != null){
			hotelService.update(h);
			String host = RequestUtil.getRequest().getRemoteHost();
			Logger logger = new Logger(new Date(), userid, host, user.getRealname());
			
			HotelLogModel hlm = new HotelLogModel();
			hlm.setContext("修改酒店资料："+h.getHotelname());
			//hlm.setHmuid(hm.getUserid());
			hlm.setHotelid(h.getId());
			hlm.setHotelname(h.getHotelname());
			hlm.setOptcode(Constant.logger.LOG_HOTEL_EDIT);
			logManager.creatHotelLog(hlm, logger);
		}else{
			//h.setUserid(hm.getUserid());
			hotelService.saveHotel(h, userid);
			String host = RequestUtil.getRequest().getRemoteHost();
			Logger logger = new Logger(new Date(), userid, host,user.getRealname());
			
			HotelLogModel hlm = new HotelLogModel();
			hlm.setContext("新增酒店："+h.getHotelname());
			//hlm.setHmuid(hm.getUserid());
			hlm.setHotelid(h.getId());
			hlm.setHotelname(h.getHotelname());
			hlm.setOptcode(Constant.logger.LOG_HOTEL_ADD);
			logManager.creatHotelLog(hlm, logger);
		}
		if(hrLi != null){
			hotelRoomService.deleteHotelRoom(h.getId());
			for(HotelRoom hr : hrLi){
				if(h.getId() != null){//查看是否已经存在改酒店的房型
					hr.setHotelid(h.getId());
					hotelRoomService.saveHotelRoom(hr);
				}else{
					hr.setHotelid(h.getId());
					hotelRoomService.saveHotelRoom(hr);
				}
			}
		}
		return new ResponseWrapTo(CodeType.success, "资料保存成功", null).toJson();
	} 
	
	/**
	 * 
		 * @description	获取酒店详情
		 * @author  han1088
		 * @param hotelid
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHoteDetail", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST  })
	public String getHoteDetail(Integer hotelid){
		Hotel h = hotelService.getHotelById(hotelid);
		Systemuser user = (Systemuser) RequestUtil.getSessionAttribute(Constant.CMS_SESSION_LOGIN_USER);
		String userid = user.getUserid();
		SysUserHotel sh = sysUserHotelService.getBindHotelByUidHid(userid,hotelid);
		if(sh == null){
			return new ResponseWrapTo(401, "你没有权限查看该酒店的详情", null).toJson();
		}
		if(h.getArea() != null){
			AreaModel[] ams = AreaHelp.getInstance().getAreaModels(h.getArea().toString());
			h.setAreaModel(ams);
		}
		List<HotelRoom> hrLi = hotelRoomService.findHotelRoomByHotelId(h.getId());
		JSONObject js = new JSONObject();
		js.put("hotel", h);
		js.put("hotelroom", hrLi);
		return new ResponseWrapTo(CodeType.success, "数据获取成功", js).toJson();
	}
	
	/**
	 * 
		 * @description	获取酒店列表
		 * @author  han1088
		 * @param startDate起始时间
		 * @param endDate终止时间
		 * @param state状态
		 * @param sortType排序
		 * @param areaCode区域码
		 * @param condition条件
		 * @param pageNo当前页码
		 * @param isArrears是否欠款1是2否
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHotelList", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST})
	public String getHotelList(String startDate, String endDate,Integer state, Integer sortType
			, Integer areaCode, String condition,Integer pageNo, Integer isArrears){
		Pager<Hotel> data = hotelService.findHoteByPage(startDate,  endDate, state,  sortType
				,  areaCode,  condition, pageNo, isArrears);
		return new ResponseWrapTo(CodeType.success, "数据获取成功", data).toJson();
	}
	
	@ResponseBody
	@RequestMapping(value = "exportHotelList", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET,RequestMethod.POST})
	public void exportHotelList(HttpServletResponse resp, HttpServletRequest req,String startDate, String endDate,Integer state, Integer sortType
			, Integer areaCode, String condition,Integer isArrears){
		List<Hotel> data = hotelService.exportHotelList(startDate,  endDate, state,  sortType
				,  areaCode,  condition, isArrears);
		String filename = "酒店.xls";
		resp.setHeader("Content-Type", "application/octet-stream");
		try {
			resp.setHeader("Content-Disposition", "attachment;filename=" + HssfUtil.buildAttachmentFileName(req, filename));
			List<Object[]> datas = new ArrayList<Object[]>();
			String[] columnNames = new String[] { "酒店名称", "所在地区", "类型","注册时间", 
					"清洁难度", "帮工单价", "酒店单价","授信额度","状态","管家数量"};
			for(Hotel h : data){
				HotelRoom r= hotelRoomService.getCriterionRoom(h.getId());
				List<HotelHmanager> hhm = hhmService.getBindHotelManager(h.getId(), null, 1);
				Object[] dataObj = new Object[columnNames.length];
				dataObj[0] = h.getHotelname();
				String address = "";
				if(h.getArea() != null){
					AreaModel[] area = AreaHelp.getInstance().getAreaModels(h.getArea().toString());
					for(AreaModel a:area){
						address = address+a.getName();
					}
				}
				
				dataObj[1] = address;
				if(h.getHoteltype() == null){
					dataObj[2] = "未设置类型";
				}else{
					if(h.getHoteltype().intValue() == Constant.HOTEL_TYPE_V.intValue()){
						dataObj[2] = "五星";
					}else if(h.getHoteltype().intValue() == Constant.HOTEL_TYPE_IV.intValue()){
						dataObj[2] = "四星";
					}else if(h.getHoteltype().intValue() == Constant.HOTEL_TYPE_III.intValue()){
						dataObj[2] = "三星";
					}else if(h.getHoteltype().intValue() == Constant.HOTEL_TYPE_II.intValue()){
						dataObj[2] = "连锁";
					}else if(h.getHoteltype().intValue() == Constant.HOTEL_TYPE_I.intValue()){
						dataObj[2] = "其他";
					}
				}
				dataObj[3] = h.getCreattime();
				dataObj[4] = h.getLevel();
				if(r != null){
					dataObj[5] = r.getEmprice();
					dataObj[6] = r.getHotelprice();
				}else{
					dataObj[5] = "";
					dataObj[6] = "";
				}
				dataObj[7] = h.getOverdraft();
				dataObj[8] = "未知";
				if(h.getState().intValue() == Constant.HOTEL_STATE_WAITAUTH){
					dataObj[8]="待审核";
				}else if(h.getState().intValue() == Constant.HOTEL_STATE_PASS){
					dataObj[8]="通过审核";
				}else if(h.getState().intValue() == Constant.HOTEL_STATE_NOPASS){
					dataObj[8]="未通过审核";
				}else if(h.getState().intValue() == Constant.HOTEL_STATE_STOP){
					dataObj[8]="已冻结";
				}
				dataObj[9]=hhm.size();//管家数量
				datas.add(dataObj);
			}
			HssfUtil.writeHssf("酒店表", columnNames, datas, filename, resp.getOutputStream());
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 
		 * @description	
		 * @author  han1088
		 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "getHotelCountGroupDate", produces = "application/json;charset=UTF-8", method = { RequestMethod.POST, RequestMethod.GET })
	public String getHotelCountGroupDate(){
		Map<String, Integer> data = hotelmanagerService.getHotelCount();
		return new ResponseWrapTo(CodeType.success, "", data).toJson();
	}
}
